<?php TPL::output('global/header.tpl.htm'); ?>

    <div class="aw-container-wrap">
        <div class="container aw-publish aw-publish-article">
            <div class="row">
                <div class="aw-content-wrap clearfix">
                    <div class="col-sm-12 col-md-9 aw-main-content">
                        <!-- tab 切换 -->
                        <ul class="nav nav-tabs aw-nav-tabs active">
                            <?php if (is_website()) { ?>
                            <li><a href="publish/suggest/"><?php _e('建议'); ?></a></li>
                            <?php } ?>
                            <?php if (check_extension_package('ticket') && get_setting('ticket_enabled') == 'Y' && $this->user_info['permission']['publish_ticket']) { ?>
                            <li><a href="ticket/publish/"><?php _e('工单'); ?></a></li>
                            <?php } ?>
                            <li class="active"><a href="publish/article/"><?php _e('文章'); ?></a></li>
                            <?php if ($this->user_info['permission']['publish_question']) { ?>
                                <li><a href="publish/"><?php _e('问题'); ?></a></li>
                            <?php } ?>

                            <h2 class="hidden-xs"><i class="icon icon-ask"></i> <?php _e('发起'); ?></h2>
                        </ul>
                        <!-- end tab 切换 -->
                        <form action="publish/ajax/<?php if ($this->article_info['id']) { ?>modify<?php } else { ?>publish<?php } ?>_article/"
                              method="post" id="question_form" onsubmit="return false;">
                            <input type="hidden" name="post_hash" value="<?php echo new_post_hash(); ?>"/>
                            <input type="hidden" name="attach_access_key"
                                   value="<?php echo $this->attach_access_key; ?>"/>
                            <input type="hidden" name="article_id" id="article_id"
                                   value="<?php echo $this->article_info['id']; ?>"/>
                            <input type="hidden" name="logo_img"
                                   value="<?php echo $this->article_info['article_img']?$this->article_info['article_img']:G_STATIC_URL.'/css/default/img/default-cover.jpg'; ?>"/>
                            <input type="hidden" name="ssid" value="<?php echo $this->ssid;?>" />
                            <?php if ($this->article_category_list) { ?>
                                <select name="category_id" class="collapse" id="category_id">
                                    <option value="0">- <?php _e('请选择分类'); ?> -</option>
                                    <?php echo $this->article_category_list; ?>
                                </select>
                            <?php } ?>
                            <?php if ($this->column_list) { ?>
                                <select name="column_id" class="collapse" id="column_id">
                                    <option value="0">- <?php _e('请选择专栏'); ?> -</option>
                                    <?php foreach ($this->column_list as $column) { ?>
                                        <option value="<?php echo $column['column_id'] ?>"><?php echo $column['column_name'] ?></option>
                                    <?php } ?>
                                </select>
                            <?php } ?>
                            <div class="aw-mod aw-mod-publish">
                                <div class="mod-body">
                                    <h3><em style="color: red;">*</em><?php _e('文章标题'); ?>:</h3>
                                    <!-- 文章标题 -->
                                    <div class="aw-publish-title<?php if (!$this->article_category_list) { ?> active<?php } ?>">
                                        <input style="width: <?php echo $this->column_list ? '58%' : '78%' ?>"
                                               type="text" name="title"
                                               value="<?php echo $this->article_info['title']; ?>"
                                               class="form-control"/>
                                        <?php if ($this->article_category_list) { ?>
                                            <div class="aw-dropdown aw-question-dropdown">
                                                <i class="aw-icon i-dropdown-triangle active"></i>
                                                <p class="title"><?php _e('没有找到相关结果'); ?></p>
                                                <ul class="aw-question-dropdown-list"></ul>
                                            </div>
                                            <div class="dropdown category" <?php if ($this->column_list) { ?> style="right: 21%;" <?php } ?>>
                                                <div class="dropdown-toggle" data-toggle="dropdown">
                                                    <span id="aw-topic-tags-select-category"><?php _e('选择分类'); ?></span>
                                                    <a href="javascript:;"><i class="icon icon-down"></i></a></a>
                                                </div>
                                            </div>
                                        <?php } ?>
                                     <?php if ($this->column_list) { ?>
                                        <div class="dropdown column">
                                            <div class="dropdown-toggle" data-toggle="dropdown">
                                                <span id="aw-topic-tags-select-column"><?php _e('选择专栏'); ?></span>
                                                <a href="javascript:;"><i class="icon icon-down"></i></a>
                                            </div>
                                        </div>
                                    <?php } ?>
                                    </div>

                                    <!-- end 文章标题 -->
                                    <?php if (get_setting('upload_enable') == 'Y') { ?>
                                        <h3><?php _e('文章封面'); ?>:</h3>
                                        <div class="side-bar">
                                            <dl>
                                                <dt class="pull-left">
                                                    <img class="aw-border-radius-5"
                                                         src="<?php if ($this->article_info['article_img']) {
                                                             echo $this->article_info['article_img'];
                                                         } else {
                                                             echo G_STATIC_URL . '/css/default/img/default-cover.jpg';
                                                         } ?>"
                                                         id="logo_img" style="height: 100px;width: 100px;"></dt>
                                                <dd class="pull-left">
                                                    <h5><?php _e('封面设置');?></h5>
                                                    <p><?php _e('支持 jpg、gif、png 等格式的图片 建议图片尺寸为240*150');?></p>
                                                    <a class="btn btn-mini btn-success" id="logo_uploader"
                                                       href="javascript:;"><?php _e('上传封面');?></a>
                                                    <span id="logo_uploading_status" class="collapse"><i
                                                                class="aw-loading"></i> <?php _e('文件上传中...'); ?></span>
                                                </dd>
                                            </dl>
                                        </div>
                                        <div class="clearfix"></div>
                                    <?php } ?>
                                    <h3><?php _e('文章内容'); ?>:</h3>
                                    <div class="aw-mod aw-editor-box">
                                        <div class="mod-head">
                                            <div class="wmd-panel">
                                        <?php  if(get_hook_config('editor')['type']['value']=='ueditor'):?> 
                                        <script id="wmd-input" name="message" type="text/plain"><?php echo $this->article_info['message']; ?></script>

                                        <?php  elseif(get_hook_config('editor')['type']['value']=='ckeditor'):?>    
                                                <textarea class="wmd-input form-control autosize editor" id="wmd-input" rows="15" name="message"><?php echo $this->article_info['message']; ?></textarea>
                                        <?php else:?>
                                            <textarea style="display: none;" id="wangcontent" rows="15" name="message"><?php echo $this->article_info['message']; ?></textarea>
                                            <div id="wmd-input">
                                                
                                            </div>
                                        <?php endif;?>

                                            </div>
                                        </div>
                                        <div class="mod-body">

                                            <p class="text-color-999"><span class="pull-right text-color-999" id="draft_detail_message">&nbsp;</span>
                                            </p>
 
                                        </div>
                                    </div>

                                    <h3><?php _e('添加话题'); ?>:</h3>
                                    <div class="aw-topic-bar" data-type="publish">
                                        <div class="tag-bar clearfix">
                                            <?php if ($_GET['topic_title']) { ?>
                                                <span class="topic-tag">
											<a class="text"><?php echo urldecode($_GET['topic_title']); ?></a>
											<a class="close" onclick="$(this).parents('.topic-tag').remove();">
												<i class="icon icon-delete"></i>
											</a>
											<button class="close aw-close" onclick="">×</button></span><input
                                                        type="hidden"
                                                        value="<?php echo urldecode($_GET['topic_title']); ?>"
                                                        name="topics[]"/>
                                                </span>
                                            <?php } ?>

                                            <?php if ($_POST['topics']) { ?>
                                                <?php foreach ($_POST['topics'] AS $key => $val) { ?>
                                                    <span class="topic-tag">
											<a class="text"><?php echo $val; ?></a>
											<input type="hidden" value="<?php echo $val; ?>" name="topics[]"/>
										</span>
                                                <?php } ?>
                                            <?php } else if ($this->article_topics) { ?>
                                                <?php foreach ($this->article_topics AS $key => $val) { ?>
                                                    <span class="topic-tag">
											<a class="text"><?php echo $val['topic_title']; ?></a>
											<input type="hidden" value="<?php echo $val['topic_title']; ?>"
                                                   name="topics[]"/>
										</span>
                                                <?php } ?>
                                            <?php } ?>

                                            <span class="aw-edit-topic icon-inverse"><i
                                                        class="icon icon-edit"></i> <?php _e('编辑话题'); ?></span>
                                        </div>
                                    </div>

                                    <?php if ($this->recent_topics) { ?>
                                        <h3><?php _e('最近话题'); ?>:</h3>
                                        <div class="aw-topic-bar">
                                            <div class="topic-bar clearfix">
                                                <?php foreach ($this->recent_topics as $key => $val) { ?>
                                                    <span class="topic-tag"
                                                          onclick="$('#aw_edit_topic_title').val('<?php echo $val; ?>');$('.add').click();$(this).hide();">
											<a class="text">
												<?php _e($val); ?>
											</a>
										</span>
                                                <?php } ?>
                                            </div>
                                        </div>
                                    <?php } ?>

                                    <?php if ($this->human_valid) { ?>
                                        <div class="aw-auth-img clearfix">
                                            <div class="embed-captcha pull-right" style="width: 260px;"></div>
                                            <p class="wait pull-right">正在加载验证码......</p>
                                           <!--  <em class="auth-img pull-right"><img src=""
                                                                                onclick="this.src = G_BASE_URL + '/account/captcha/' + Math.floor(Math.random() * 10000);"
                                                                                id="captcha"/></em>
                                           <input class="pull-right form-control" type="text" name="seccode_verify"
                                                  placeholder="验证码"/> -->
                                        </div>
                                    <?php } ?>
                                </div>
                                <div class="mod-footer clearfix">
                                    <?php if (get_setting('integral_system_enabled') == 'Y') { ?><a
                                            href="integral/rule/" target="_blank">[<?php _e('积分规则'); ?>]</a><?php } ?>
                                    <span class="aw-anonymity">
									<?php if ($this->article_info['id'] AND ($this->user_info['permission']['is_administortar'] OR $this->user_info['permission']['is_moderator'])) { ?>
                                        <label><input type="checkbox" class="pull-left" value="1" name="do_delete"/>
                                            <?php _e('删除文章'); ?></label>
                                    <?php } ?>
                                    <?php if(get_setting('draft_enabled')!='N'){ ?>
                                        <a id="saveDraft" data-type="article"><?php _e('保存草稿'); ?></a>
                                    <?php } ?>
								</span>
                                    <a class="btn btn-large btn-success btn-publish-submit" id="publish_submit"
                                       <?php if (!$this->human_valid) { ?>onclick="AWS.ajax_post($('#question_form')); return false;"<?php } ?> ><?php _e('确认发起'); ?></a>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!-- 侧边栏 -->
                    <div class="col-sm-12 col-md-3 aw-side-bar hidden-xs">
                        <!-- 文章发起指南 -->
                        <div class="aw-mod publish-help">
                            <div class="mod-head">
                                <h3><?php _e('文章发起指南'); ?></h3>
                            </div>
                            <div class="mod-body">
                                <p><b>• <?php _e('文章标题'); ?>:</b> <?php _e('请用准确的语言描述您发布的文章思想'); ?></p>
                                <p><b>• <?php _e('文章补充'); ?>
                                        :</b> <?php _e('详细补充您的文章内容, 并提供一些相关的素材以供参与者更多的了解您所要文章的主题思想'); ?></p>
                                <p><b>• <?php _e('选择话题'); ?>
                                        :</b> <?php _e('选择一个或者多个合适的话题, 让您发布的文章得到更多有相同兴趣的人参与. 所有人可以在您发布文章之后添加和编辑该文章所属的话题'); ?>
                                </p>
                            </div>
                        </div>
                        <!-- end 文章发起指南 -->
                    </div>
                    <!-- end 侧边栏 -->
                </div>
            </div>
        </div>
    </div>
<?php 
hook('editor','init',['name'=>'wmd-input','cat'=>'article']);
?>

    <script type="text/javascript">
        var ATTACH_ACCESS_KEY = '<?php echo $this->attach_access_key; ?>';
        var CATEGORY_ID = <?php echo $this->article_info['category_id']; ?>;
        var COLUMN_ID = <?php echo $this->article_info['column_id']; ?>;
        var PUBLISH_TYPE = 'article';
    var editor_type="<?php echo get_hook_config('editor')['type']['value'];?>"
        
    <?php if (get_setting('upload_enable') == 'Y' AND get_setting('advanced_editor_enable' == 'Y')): ?>
        var logoUpload = new FileUpload('avatar', $('#logo_uploader'), $('#logo_img'), G_BASE_URL + '/publish/ajax/logo_upload/', {
            loading_status: '#logo_uploading_status',
            tag: 'logo',
            accept:'image/*'
        }, function () {
            $('input[name="logo_img"]').val($('#logo_img').attr('src'));
        });
        <?php endif;?>
        QUESTION_ID = <?php echo $this->article_info['id']?$this->article_info['id']:0; ?>;
        <?php if ($this->human_valid) { ?>
        var handlerEmbed = function (captchaObj) {
            $('#publish_submit').click(function(){
                var validate = captchaObj.getValidate();
                if (!validate) {
                    AWS.alert("请先完成验证");
                    return false;
                } else{
                    AWS.ajax_post($('#question_form'));
                    captchaObj.reset(); // 调用该接口进行重置 
                    return false;
                }
            });
            // 将验证码加到id为captcha的元素里，同时会有三个input的值：geetest_challenge, geetest_validate, geetest_seccode
            captchaObj.appendTo(".embed-captcha");
            captchaObj.onReady(function () {
                $(".wait").css('display','none');
            });
        };

        $.ajax({
            // 获取id，challenge，success（是否启用failback）
            url: G_BASE_URL+ "/account/slide_captcha/?t=" + (new Date()).getTime()+"&client_type='web'", // 加随机数防止缓存
            type: "get",
            dataType: "json",
            success: function (data) {
                var dataObj = eval('(' + data.rsm + ')');
                // 使用initGeetest接口
                // 参数1：配置参数
                // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它做appendTo之类的事件
                initGeetest({
                    gt: dataObj.gt,
                    challenge: dataObj.challenge,
                    new_captcha: dataObj.new_captcha,
                    offline: !dataObj.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                    product: "embed", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
                    width: '100%' // 设置按钮宽度, 与父元素宽度一致
                }, handlerEmbed);
            }
        });
    <?php } ?>
    </script>

<?php TPL::output('global/footer.tpl.htm'); ?>